package engine;

import java.util.ArrayList;
import java.util.List;

import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import engine.dataobjects.MailItem;
import engine.dataobjects.xml.To;
import engine.services.IMailService;


public class MailService {
//	@Test
//	@Ignore
	public void testMailService() {
		try {
			//System.setProperty("user.dir", "C:/Users/Ilanap/Personal/projects/MailPusher/src/main/resources");
			
			String userDir  = System.getProperty("user.dir").replace("\\\\", "/");
			System.setProperty("log4j.configuration","file:/"+userDir+"/src/main/resources/META-INF/log4j.xml");
			ApplicationContext context = new FileSystemXmlApplicationContext(userDir+"/src/main/resources/META-INF/ScheduledMailerApplicationContext.xml");
			IMailService service = (IMailService)context.getBean("mailService");
			MailItem message = new MailItem();
			message.setName("TestMessage");
			List<String> to = new ArrayList<String>();
			to.add("ilana.paktor@amdocs.com");
			message.setTo(to);
			service.mail(message );
			System.out.println("done");
			
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
}
